Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution #433

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Solution #433

wants to merge 3 commits into from

Conversation

ab3MN
Copy link

@ab3MN ab3MN commented Dec 2, 2024

Implemented solution

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your hard work on the 'Bulls & Cows' game! 🎉 While your implementation is mostly correct, there are a few critical issues that need to be addressed to ensure the game functions as intended.

  1. Random Number Generation: The logic for generating a 4-digit number with unique digits needs improvement. Currently, it may produce numbers with fewer than 4 digits or with leading zeros. Please adjust the logic to ensure the number is always 4 digits long, with the first digit non-zero and all digits unique.

  2. User Input Handling: When the input is invalid, the program should not proceed to calculate bulls and cows. Instead, it should prompt the user to try again. Adding a return statement after displaying the invalid input message will help in preventing further execution and allow the user to input again.

Once these issues are resolved, your code will be ready for approval. Keep up the great work, and I'm confident you'll nail these changes! 💪

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review button in the Reviewers tab.

src/app.js Outdated
Comment on lines 21 to 23
if (!checkIsValidUserInput(text)) {
stdout.write(INVALID_INPUT_MESSAGE);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, if the input is invalid, the program only writes an error message but does not return or prompt the user to input again. You should add a return statement after writing the INVALID_INPUT_MESSAGE to prevent further execution of the code block and prompt the user to try again.

const uniqRandomNumbers = new Set();

while (uniqRandomNumbers.size !== 4) {
const randomNumber = Math.floor(1 + Math.random() * 9);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current logic for generating random numbers only produces digits from 1 to 9. This ensures no leading zero, but the logic for ensuring exactly 4 unique digits is flawed. Consider modifying the logic to ensure the first digit is non-zero and the remaining digits are unique, potentially by generating the first digit separately and then filling the rest.

uniqRandomNumbers.add(randomNumber);
}

return Number(Array.from(uniqRandomNumbers).join(''));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conversion of the set to a number may result in fewer than 4 digits if the set contains leading zeros. Ensure that the number is always 4 digits long by adjusting the logic to handle leading zeros appropriately.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Great job on implementing the 'Bulls & Cows' game! 🎉 Your code is mostly correct, but there are a couple of critical issues that need attention to ensure the game functions as intended:

  1. Random Number Generation: The generateRandomNumber function is designed to create a 4-digit number with unique digits. However, due to the unordered nature of sets, the current logic might not always produce a valid 4-digit number. Consider using an array to maintain the order of digits and ensure the first digit is always non-zero.

  2. User Input Handling: In app.js, the program currently continues execution even when the user input is invalid. To prevent this, add a return statement after displaying the invalid input message. This will ensure that the user is prompted to input again without proceeding to calculate bulls and cows.

These improvements are crucial for the functionality of the game. Addressing them will enhance the user experience and ensure the game operates correctly.

Remember, the decision to approve your pull request is to help you move forward with your learning journey. Please review the comments and make the necessary changes to improve your code. Keep up the good work, and continue learning from these experiences! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

Comment on lines +21 to +23
if (!checkIsValidUserInput(text)) {
stdout.write(INVALID_INPUT_MESSAGE + PROMPT_MESSAGE);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To prevent the program from proceeding with invalid input, add a return statement after displaying the invalid input message. This will ensure that the user is prompted to input again without calculating bulls and cows.

digits.add(randomDigit);
}

return Number(Array.from(digits).join(''));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation may not guarantee a 4-digit number due to the unordered nature of sets. Consider using an array to maintain the order of digits and ensure the first digit is always non-zero.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants